<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>08--姓名案例--watch</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="app">
            姓：<input type="text"  v-model="firstName"/><br><br>
            名：<input type="text" v-model="lastName" /><br><br>
            <h1>姓名：{{fullName}}</h1>
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        
        new Vue({
            el:"#app",
            data:{
                firstName:"zang",
                lastName:"san",
                fullName:"zhang-san"
            },
            watch:{
                firstName(value){
                    this.fullName = value +"-"+ this.lastName
                },
                lastName(value){
                    setTimeout(()=>{
                        this.fullName = this.firstName +"-"+value
                    },1000)
                }
            }
        })
    </script>
</html>